package net.borderwars.webstartclient;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;

/**
 * @author ehubbard
 *         Date: Aug 10, 2005
 *         Time: 11:26:18 AM
 */
public class RobotTreeModel extends DefaultTreeModel {
    private static DefaultMutableTreeNode publicRobots;
    private static DefaultMutableTreeNode testRobots;
    private static DefaultMutableTreeNode productionRobots;

    public static RobotTreeModel getModel () {

        DefaultMutableTreeNode root = new DefaultMutableTreeNode ("Our Developer");

        publicRobots = new DefaultMutableTreeNode ("Public Domain Robots");
        testRobots = new DefaultMutableTreeNode ("Robots in Testing");
        productionRobots = new DefaultMutableTreeNode ("Production Robots");

        root.add (publicRobots);
        root.add (testRobots);
        root.add (productionRobots);

        RobotTreeModel rtm = new RobotTreeModel (root);
        return (rtm);
    }

    public boolean getSelectionACategory (DefaultMutableTreeNode dmtn) {
        if (dmtn.equals (publicRobots)) {
            return true;
        }
        if (dmtn.equals (testRobots)) {
            return true;
        }
        if (dmtn.equals (productionRobots)) {
            return true;
        }
        return (false);
    }

    public void addRobot (DefaultMutableTreeNode category, Object o) {
        synchronized (super.getRoot ()) {
            DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode (o, false);
            dmtn.setAllowsChildren (false);
            category.add (dmtn);
            nodeChanged (category);
        }
    }

    public RobotTreeModel (TreeNode root) {
        super (root);

    }

}
